package com.suanfa.collect;

import java.util.Collections;
import java.util.stream.Collectors;

public class BadVersion {


    static final int bad = 4;

    public static void main(String[] args) {
        int version  = 5;
        System.out.println(firstBadVersion(5));
    }

    public static int firstBadVersion(int n) {
        int start = 1;
        int end = n;
        if( n == 1){
            return n;
        }
        while(start < end){
            int mid = start+ (end - start)/2;//需要防止大数据导致的溢出
            if(isBadVersion(mid)){
                end = mid;
            }else{
                start = mid+1;
            }

        }
        return start;

    }

    public static boolean isBadVersion(int n){
        return n == bad;
    }

}
